version: '3'

services:

        app:
            build:
                context: ./docker/php-fpm
                args:
                    - timezone=${TZ}
            volumes:
                - ./app:/app:rw,cached
                - app_log:/app/var/log
            env_file:
                - .env
            depends_on:
                - mysql
            environment:
                XDEBUG_CONFIG: idekey=PHPSTORM remote_host=${XDEBUG_REMOTE_HOST} remote_port=9000
                PHP_IDE_CONFIG: serverName=${NGINX_HOST}
            container_name: app

        nginx:
            build:
                context: ./docker/nginx
                args:
                    - nginx_host=${NGINX_HOST}
            ports:
                - "80:80"
                - "443:443"
            depends_on:
                - app
            volumes:
                - ./app:/app:ro
                - ./docker/nginx/default.template:/etc/nginx/conf.d/default.template
                - nginx_log:/var/log/nginx
            env_file:
                - .env
            command: /bin/bash -c "envsubst '$$NGINX_HOST'
                < /etc/nginx/conf.d/default.template
                > /etc/nginx/conf.d/default.conf
                && exec nginx -g 'daemon off;'"
            container_name: nginx

        mysql:
            build:
                context: ./docker/db
                dockerfile: Dockerfile.mysql
            volumes:
                - ./.data/mysql:/var/lib/mysql:rw
            env_file:
                - .env
            ports:
                - "3306:3306"
            container_name: db      

        redis:
            build:
                context: ./docker/redis
            container_name: redis

volumes:
    nginx_log:
    app_log:
